# -*- coding: utf-8 -*-
# @Time : 2022/1/4 16:15
# @Author : Limusen
# @File : demo_excel_20

import os
import xlrd3

abs_path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(abs_path, '..', 'files', 'baidu_page.xls')

# 创建excel对象
work_book = xlrd3.open_workbook(file_path)
# 创建表对象
sheet = work_book.sheet_by_name("baidu")

# 获取行
print(sheet.nrows)
# 　获取列
print(sheet.ncols)
# 获取数据
print(sheet.cell_value(2, 4))


# 获取总行数
def nrows():
    return sheet.nrows


# 获取总列数
def ncols():
    return sheet.ncols


# 　取出excel的全部数据
all_excel_data = []
for row in range(nrows()):
    row_data = []
    for cols in range(ncols()):
        cell_value = sheet.cell_value(row, cols)
        row_data.append(cell_value)
    all_excel_data.append(row_data)
for i in all_excel_data:
    print(i)
